We have a lecture hall at our disposal.
Lecturers place orders in which they specify at what time their lecture begins and at what time it ends.
We want to make maximal use of the hall.
We accept some orders and reject others and our aim is to achieve the longest possible time of lectures in the hall.
We assume that at the moment when one lecture ends another can begin.
Task
Write a program that:
reads orders of lecturers from the standard input,
computes the maximal possible time of lectures,
writes the result to the standard output.
Input
In the first line of the standard input there is written one positive integer , (),
which is the number of orders.
In each of the following lines there are written two integers and ,
separated by a single space, .
Such a pair of integers represents an order for the hall.
The lecture is to begin at time and end in time (a lecturer needs the hall in time
represented by an open interval).
Output
In the first line of the standard output there should be written the maximal possible time of lectures.
W razie problemów technicznych ze Szkopułem, prosimy o kontakt mailowy pod adresem szkopul@fri.edu.pl.
Jeśli chciałbyś porozmawiać o zadaniach, rozwiązaniach lub problemach technicznych, odwiedź nasze serwery na Discordzie. Są one moderowane przez społeczność, ale członkowie zespołu wsparcia również aktywnie się tam udzielają.